﻿using Domain.Entity;
using Domain.Repository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repositorys
{
    public class SSDRepository : ISSDRepository
    {
        private readonly MyDbContext myDbContext;

        public SSDRepository(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }
        public async Task<List<SSD>> SelectSSDAsync()
        {
            return await myDbContext.SSD.ToListAsync();
        }
        
        public async Task<List<SSD>> SelectSSDStandardIdAsync(string StandardId)
        {
            return await myDbContext.SSD.Where(c => c.StandardId == StandardId).ToListAsync();
        }

        public async Task<bool> AddSSDAsync(SSD ssd)
        {
            myDbContext.SSD.Add(ssd);
            return await myDbContext.SaveChangesAsync() > 0;
        }
        //删除
        public async Task<bool> DeleteSSDAsync(int id)
        {
            SSD ssd = await myDbContext.SSD.FindAsync(id);
            if (ssd == null)
            {
                return false;
            }

            myDbContext.SSD.Remove(ssd);
            int changes = await myDbContext.SaveChangesAsync();
            return changes > 0;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="ssd"></param>
        /// <returns></returns>
        public async Task<bool> UpdateSSDAsync(SSD ssd)
        {
            myDbContext.SSD.Update(ssd);
            return await myDbContext.SaveChangesAsync() > 0;
        }
    }
}
